package com.zmzncs.lmtc.module.customer.controller;


import com.zmzncs.lmtc.common.pojo.LoginUser;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.pojo.enums.WhetherEnum;
import com.zmzncs.lmtc.common.pojo.enums.optionalvalue.customer.CarTypeEnum;
import com.zmzncs.lmtc.common.util.*;
import com.zmzncs.lmtc.module.customer.pojo.car.Car;
import com.zmzncs.lmtc.module.customer.pojo.car.CarDTO;
import com.zmzncs.lmtc.module.customer.pojo.car.CarVO;
import com.zmzncs.lmtc.module.customer.pojo.customer.CustomerDTO;
import com.zmzncs.lmtc.module.customer.service.CarService;
import com.zmzncs.lmtc.module.customer.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 客户-车辆 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-08-31
 */
@Api(tags = "客户车牌")
@RestController
@RequestMapping("/customer/car")
@Validated
@Slf4j
public class CarController {

    @Autowired
    CarService carService;
    @Autowired
    CustomerService customerService;
    @Autowired
    HttpServletRequest request;

    @ApiOperation(value = "获取客户车辆")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping(value = "/getCustomerCarList")
    public Rest<List<CarVO>> getCustomerCarList() {
        List<CarDTO> customerCarList = carService.getCustomerCarList();
        List<CarVO> carVOList = JsonUtil.listTransform(customerCarList, CarVO.class);
        return RestUtil.success(carVOList);
    }

    @ApiOperation(value = "添加客户车牌")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "carNumber", value = "车牌号", required = true),
    })
    @PostMapping(value = "/addCustomerCar")
    @Transactional
    public Rest addCustomerCar(@NotBlank String carNumber) {
        carService.addCustomerCar(carNumber);
        return RestUtil.success();
    }

    @ApiOperation(value = "删除客户车牌")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "id", value = "客户车牌id", required = true),
    })
    @PostMapping(value = "/deleteCustomerCar")
    public Rest deleteCustomerCar(@NotNull Long id) {
        carService.deleteCustomerCar(id);
        return RestUtil.success();
    }

}

